﻿using System;
using System.Collections.Generic;
using System.Text;

namespace BadApplePlayer
{
    public static class CommonInfo
    {
        static CommonInfo() {
            BadAppleResource = (BadAppleRes)ByteToObject(System.IO.File.ReadAllBytes("BadAppleRes.r"));
        }
        public static BadAppleRes BadAppleResource;
        /// <summary>
        /// 二进制流还原成对象
        /// </summary>
        /// <param name="bytes">二进制流</param>
        /// <returns>反序列化对象</returns>
        public static object ByteToObject(byte[] bytes) {
            try {
                System.IO.MemoryStream stream = new System.IO.MemoryStream(bytes);
                System.Runtime.Serialization.IFormatter bf = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
                Object reobj = bf.Deserialize(stream);
                stream.Close();
                return reobj;
            } catch (Exception ex) {
                System.Windows.Forms.MessageBox.Show(ex.Message);
                return null;
            }
        }
    }
}
